package com.atguigu.registration.user.service.impl;

import com.atguigu.registration.cmn.client.DictFeignClient;
import com.atguigu.registration.enums.DictEnum;
import com.atguigu.registration.model.user.Patient;
import com.atguigu.registration.user.mapper.PatientMapper;
import com.atguigu.registration.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Jiang Yizhi
 * @Date: 2022/5/7 3:49 PM
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private DictFeignClient dictFeignClient;

    @Override
    public List<Patient> findAllUserId(Long userId) {
        /** 根据userId查询所有就诊人信息信息列表 */
        QueryWrapper<Patient> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        List<Patient> patientList= baseMapper.selectList(wrapper);
        /** 通过远程调用，得到编码对应具体内容，查询数据字典表内容 */
        patientList.stream().forEach(item -> {
            /** 其他参数的封装 */
            this.packPatient(item);
        });
        return patientList;
    }

    @Override
    public Patient getPatientById(Long id) {
        Patient patient = baseMapper.selectById(id);
        return this.packPatient(patient);
    }

    private Patient packPatient(Patient patient) {
        String certificatesTypeString = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
        //联系人证件类型
        String contactsCertificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getContactsCertificatesType());
        //省
//        String provinceString = dictFeignClient.getName(patient.getProvinceCode());
//        //市
//        String cityString = dictFeignClient.getName(patient.getCityCode());
//        //区
//        String districtString = dictFeignClient.getName(patient.getDistrictCode());
        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
//        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("provinceString","北京");
        patient.getParam().put("cityString","北京");
        patient.getParam().put("districtString","朝阳区");
//        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
        patient.getParam().put("fullAddress", "北京北京朝阳区");
        return patient;

    }
}
